package com.woniuxy.utils;

import org.springframework.cglib.proxy.Enhancer;
import org.springframework.cglib.proxy.InvocationHandler;

import java.lang.reflect.Method;

public class CgLibProxyInstance {
    public Object createSon(Object proxyedObject){
        return Enhancer.create(proxyedObject.getClass(), new InvocationHandler() {
            @Override
            public Object invoke(Object o, Method method, Object[] objects) throws Throwable {
                System.out.println("cglib增强了目标类的方法，进入前：");
                Object invoke = method.invoke(proxyedObject, objects);
                System.out.println("cglib增强了目标类的方法，执行后!");
                return invoke;
            }
        });
    }
}
